<template>
  <div class="accountList">
    <el-card style=" padding-top: 30px">
      <div style="text-align: center;">
      <div>
        {{ newsDetail.title }}
      </div>
      <div class="title">
        <span>发布时间：{{ newsDetail.createTime }}</span>
        <span style="margin-left: 40px">浏览量：{{ newsDetail.view }}</span>
        <span style="margin-left: 40px" @click="getUrl"
          >来源：<span style="color: #409eff; cursor: pointer">{{
            newsDetail.sourceTitle
          }}</span></span
        >
      </div>
       
      </div>
     <div v-html="newsDetail.content"></div>
      <div v-for="(item, index) in newsDetail.attachments" :key="index">
        <div class="pdf-style" @click="exportClick(item)">{{ item.name }}</div>
      </div>
    </el-card>
    <div v-if="title == '审核'" class="audit-btns">
      <el-button type="danger" @click='auditClick(false)'>审核不通过</el-button>
      <el-button type="primary"  @click='auditClick(true)' style="margin-left: 30px">审核通过</el-button>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      newsDetail: {},
      id: "",
      title: "",
    };
  },
  methods: {
  async  auditClick(status){
     const confirm = await this.$confirm(
          '确定执行当前操作吗？',
          "提示",
          {
            confirmButtonText: "确认",
            cancelButtonText: "取消",
            type: "warning",
          }
        ).catch(() => false);
        if (!confirm) return false;
          const res = await this.$api.auditClick({id:this.id,status:status});
          if (res.data.code == "00000") {
            this.$message.success("操作成功");
                  this.$router.go(-1);

          }
     
    },
    exportClick(item) {
      let blob = new Blob([item]);
      var link = document.createElement("a");
      var href = window.URL.createObjectURL(blob);
      link.href = href;
      link.download = item.name;
      document.body.appendChild(link);
      link.click();
      document.body.removeChild(link);
      window.URL.revokeObjectURL(href);
      this.$message.success("请稍等,正在导出");
    },
    async getNewsDetail() {
      const res = await this.$api.operationDetail(this.id);
      this.newsDetail = res.data.result;
        this.newsDetail.content = this.newsDetail.content.replace(
              /<img /g,
              '<img style="width:100%" '
            );
    },
    getUrl() {
      let url;
      if (
        this.newsDetail.sourceUrl.indexOf("http") == -1 ||
        this.newsDetail.sourceUrl.indexOf("https") == -1
      ) {
        url = `http://${this.newsDetail.sourceUrl}`;
      } else {
        url = this.newsDetail.sourceUrl;
      }
      window.location.href = url;
    },
  },
  created() {
    this.id = this.$route.query.id;
    this.title = this.$route.query.title;
    document.title = this.$route.query.title;
    this.getNewsDetail();
  },
};
</script>
<style  lang='less' scoped>
.accountList {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 20px;
  .title {
    font-size: 14px;
    margin-top: 30px;
  }
  .pdf-style {
    background-color: #f9f9f9;
    padding: 10px 0;
    text-align: left;
    margin-bottom: 5px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
  }
  .audit-btns {
    margin-top: 40px;
    text-align: center;
  }

}
</style>
